Wicked Cool Shell Scripts by Dave Taylor & Brandon Perry
Author:Dave Taylor & Brandon Perry
Language: eng
Format: epub, mobi
Publisher: No Starch Press
Published: 2017-04-10T04:00:00+00:00
The Code
#!/bin/bash # backup--Creates either a full or incremental backup of a set of defined # directories on the system. By default, the output file is compressed and # saved in /tmp with a timestamped filename. Otherwise, specify an output # device (another disk, a removable storage device, or whatever else floats # your boat). compress="bzip2" # Change to your favorite compression app. inclist="/tmp/backup.inclist.$(date +%d%m%y)" output="/tmp/backup.$(date +%d%m%y).bz2" tsfile="$HOME/.backup.timestamp" btype="incremental" # Default to an incremental backup. noinc=0 # And here's an update of the timestamp. trap "/bin/rm -f $inclist" EXIT usageQuit() { cat << "EOF" >&2 Usage: $0 [-o output] [-i|-f] [-n] -o lets you specify an alternative backup file/device, -i is an incremental, -f is a full backup, and -n prevents updating the timestamp when an incremental backup is done. EOF exit 1 } ########## Main code section begins here ########### while getopts "o:ifn" arg; do case "$opt" in o ) output="$OPTARG"; ;; # getopts automatically manages OPTARG. i ) btype="incremental"; ;; f ) btype="full"; ;; n ) noinc=1; ;; ? ) usageQuit ;; esac done shift $(( $OPTIND - 1 )) echo "Doing $btype backup, saving output to $output" timestamp="$(date +'%m%d%I%M')" # Grab month, day, hour, minute from date. # Curious about date formats? "man strftime" if [ "$btype" = "incremental" ] ; then if [ ! -f $tsfile ] ; then echo "Error: can't do an incremental backup: no timestamp file" >&2 exit 1 fi find $HOME -depth -type f -newer $tsfile -user ${USER:-LOGNAME} | \ ➊ pax -w -x tar | $compress > $output failure="$?" else find $HOME -depth -type f -user ${USER:-LOGNAME} | \ ➋ pax -w -x tar | $compress > $output failure="$?" fi if [ "$noinc" = "0" -a "$failure" = "0" ] ; then touch -t $timestamp $tsfile fi exit 0
Listing 6-16: The backup script
Download
Wicked Cool Shell Scripts by Dave Taylor & Brandon Perry.mobi
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7772)
Filmora Efficient Editing by Alexander Zacharias(5872)
The Infinite Retina by Robert Scoble Irena Cronin(5342)
Learn Wireshark - Fundamentals of Wireshark. by Lisa Bock(4022)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3940)
Edit Like a Pro with iMovie by Regit(3471)
Linux Administration Best Practices by Scott Alan Miller(2864)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic & Jasmin Redzepagic(2840)
MCSA Windows Server 2016 Study Guide: Exam 70-740 by William Panek(2529)
Mastering PowerShell Scripting - Fourth Edition by Chris Dent(2443)
Docker on Windows by Stoneman Elton(2323)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2317)
Creative Projects for Rust Programmers by Carlo Milanesi(2289)
Hands-On AWS Penetration Testing with Kali Linux by Karl Gilbert(2115)
Hands-On Linux for Architects by Denis Salamanca(2056)
Programming in C (4th Edition) (Developer's Library) by Stephen G. Kochan(2012)
Computers For Seniors For Dummies by Nancy C. Muir(2009)
The Old New Thing by Raymond Chen(1943)
Linux Kernel Debugging by Kaiwan N Billimoria(1770)
